home *** CD-ROM | disk | FTP | other *** search
/ TeX 1995 July / TeX CD-ROM July 1995 (Disc 1)(Walnut Creek)(1995).ISO / web / fweb / fweb-1.40 / manual / equations.sty (.txt) < prev    next >
LaTeX Document  |  1993-10-29  |  12KB  |  253 lines

  1. % This file, equations.sty (July 1990), contains a collection of macros
  2. % to aid in constructing displayed equations in LaTeX.  Written by
  3. %  Charles Karney          
  4. %  Plasma Physics Laboratory      E-mail:  Karney@Princeton.EDU
  5. %  Princeton University          Phone:   +1 609 243 2607
  6. %  Princeton, NJ 08543-0451      FAX:       +1 609 243 2662
  7. % with some ideas and macros borrowed from John Hobby and Stephen Gildea.
  8. \def\fileversion{2.0}
  9. \def\filedate{93/08/30}
  10. \def\docdate {93/08/30}
  11. % \changes{v2.0}{93/08/30}{Added optional arguments to \yesnumber and
  12. %    \begin{equation}}
  13. % --------------------USER DOCUMENTATION--------------------
  14. % Use this as a style option, e.g.,
  15. %     \documentstyle[equations]{article}
  16. % These probably don't work in conjunction with the leqno option.
  17. % This implements the following:
  18. % (1) \yesnumber turns on an equation number in an eqnarray* environment
  19. % (just as \nonumber turns it off in an eqnarray environment).  E.g.,
  20. %     \begin{eqnarray*}
  21. %        a &=& b \\
  22. %          & & + c \\
  23. %          & & + d \\
  24. %          & & + e \\
  25. %          & & + f \\
  26. %          & & + g \yesnumber
  27. %     \end{eqnarray*}
  28. %   \yesnumber takes an optional argument that will be used for the
  29. %   equation number.  The equation counter will not be incremented.
  30. %    \begin{eqnarray*}
  31. %          & & + f \\
  32. %          & & + g \yesnumber[**]
  33. %     \end{eqnarray*}
  34. % (2) The eqalign environment is just like Plain TeX's \eqalign.  E.g.,
  35. %     \begin{equation}
  36. %           \begin{eqalign}
  37. %              a &= b, \\
  38. %              c &= d.
  39. %           \end{eqalign}
  40. %     \end{equation}
  41. % Note that \begin{equation} \end{equation} or equivalent is needed.
  42. % (3) The eqalignno environment is just like Plain TeX's \eqalignno.  E.g.,
  43. %     \begin{eqalignno}
  44. %        a &= b, \label{foo}\\
  45. %        c &= d. \label{bar}
  46. %     \end{eqalignno}
  47. % Note the absence of \begin{equation} \end{equation}.  \nonumber can be used
  48. % to suppress the equation number.  eqalignno* is the same except that the
  49. % equation numbers are suppressed (unless a \yesnumber appears).
  50. % (4) The eqaligntwo environment is a two-equation per line equivalent of
  51. % eqalignno.  E.g.,
  52. %     \begin{eqaligntwo}
  53. %        a &= b, & x &= y, \label{foo} \\
  54. %        c &= d, & z &= w. \label{bar}
  55. %     \end{eqaligntwo}
  56. % eqaligntwo* is defined similarly.
  57. % (5) The cases environment is just like Plain TeX's \cases.  E.g.,
  58. %     \begin{equation}
  59. %        u(x) =
  60. %           \begin{cases}
  61. %             0, & for $x < 0$, \\
  62. %             1, & for $x \ge 0$.
  63. %           \end{cases}
  64. %     \end{equation}
  65. % Note the first column is treated as math, the second column as text.
  66. % (6) I've borrowed John Hobby's modifications to the eqnarray environment
  67. % (to fix up the spacing around the operator), and to the \big, \bigg, etc.
  68. % operators (to make them scale with the point size).
  69. % (7) I've borrowed Stephen Gildea's subequations environment, and fixed it
  70. % so that it ignores spaces after the environment and so that you can refer
  71. % both to the overall set of equations and to individual subequations.  E.g.,
  72. %     \begin{subequations} \label{foo}
  73. %       \begin{eqalignno}
  74. %          a &= b, \label{foo-a} \\
  75. %          c &= d, \label{foo-b}
  76. %       \end{eqalignno}
  77. %       text text text text ...
  78. %       \begin{equation}
  79. %          e = f. \label{foo-c}
  80. %       \end{equation}
  81. %     \end{subequations}
  82. % Now \ref{foo}, \ref{foo-a}, \ref{foo-b}, \ref{foo-c}, produce 1, 1a, 1b,
  83. % 1c.
  84. % (8) The equation number is always printed in text mode.  Normally an
  85. % equation environment would print it in math mode (with the \rm family).
  86. % This only makes a difference if \rm in text and math modes gives you
  87. % different fonts.
  88. % (8) \begin{equation} can take an optional argument that will be used for the
  89. % equation number.  The equation counter will not be incremented.
  90. %    \begin{equation}[$G'$]
  91. %        2 + 2 = 4
  92. %    \end{equation}
  93. % --------------------END OF USER DOCUMENTATION--------------------
  94. % Fix up eqnarray* so that \yesnumber and \nonumber do the obvious things 
  95. % Incorporate fixes of Peter Vanroose (peter@dit.lth.se) to make \yesnumber
  96. % actually work.
  97. \newif\if@defeqnsw \@defeqnswtrue
  98. % Has the user specified a hard-wired equation number?
  99. \newif\if@hardeqn \@hardeqnfalse
  100. % This is John Hobby's (hobby@research.att.com) version to fix up the spacing.
  101. \def\eqnarray{\stepcounter{equation}\let\@currentlabel=\theequation
  102. \if@defeqnsw\global\@eqnswtrue\else\global\@eqnswfalse\fi
  103. \tabskip\@centering\let\\=\@eqncr
  104. $$\halign to \displaywidth\bgroup\hfil\global\@eqcnt\z@
  105.   $\displaystyle\tabskip\z@{##}$&\global\@eqcnt\@ne 
  106.   \hfil$\displaystyle{{}##{}}$\hfil
  107.   &\global\@eqcnt\tw@ $\displaystyle{##}$\hfil 
  108.   \tabskip\@centering&\llap{##}\tabskip\z@\cr}
  109. \@namedef{eqnarray*}{\@defeqnswfalse\global\@eqnswfalse\eqnarray}
  110. \@namedef{endeqnarray*}{\endeqnarray}
  111. \def\yesnumber{\@ifnextchar[{\@yesnumber}{\global\@eqnswtrue}}    % ]
  112. % Set up to use an hardwired equation number in an eqnarray
  113. \def\@yesnumber[#1]{\global\@eqnswtrue
  114.     \global\@hardeqntrue\let\ref=\expandableref\xdef\@hardeqndef{#1}}
  115. % This is taken out of \@@eqncr because TeX \if nesting was misdesigned - ews
  116. \def\make@eqnnum{\if@hardeqn{\def\theequation{\@hardeqndef}\@eqnnum}\global\@hardeqnfalse\else
  117.                                  \@eqnnum\stepcounter{equation}\fi}
  118. \def\@@eqncr{\let\@tempa\relax \global\advance\@eqcnt by \@ne
  119.     \ifcase\@eqcnt \def\@tempa{& & & &}\or \def\@tempa{& & &}\or
  120.      \def\@tempa{& &}\or \def\@tempa{&}\else\fi 
  121.      \@tempa \if@eqnsw\make@eqnnum\fi
  122.      \if@defeqnsw\global\@eqnswtrue\else\global\@eqnswfalse\fi
  123.      \global\@eqcnt\z@\cr}
  124. % Several formulas like \eqalign (to go inside \begin{equation}
  125. % \end{equation} or $$ $$.
  126. \def\@eqnacr{{\ifnum0=`}\fi\@ifstar{\@yeqnacr}{\@yeqnacr}}
  127. \def\@yeqnacr{\@ifnextchar [{\@xeqnacr}{\@xeqnacr[\z@]}}
  128. \def\@xeqnacr[#1]{\ifnum0=`{\fi}\cr \noalign{\vskip\jot\vskip #1\relax}}
  129. \def\eqalign{\null\,\vcenter\bgroup\openup1\jot \m@th \let\\=\@eqnacr
  130. \ialign\bgroup\strut
  131. \hfil$\displaystyle{##}$&$\displaystyle{{}##}$\hfil\crcr}
  132. \def\endeqalign{\crcr\egroup\egroup\,}
  133. % \cases
  134. \def\cases{\left\{\,\vcenter\bgroup\normalbaselines\m@th \let\\=\@eqnacr
  135.     \ialign\bgroup$##\hfil$&\quad##\hfil\crcr}
  136. \def\endcases{\crcr\egroup\egroup\right.}
  137. % Several formulas like \eqalignno (doesn't need the $$ $$)
  138. \def\eqalignno{\stepcounter{equation}\let\@currentlabel=\theequation
  139. \if@defeqnsw\global\@eqnswtrue\else\global\@eqnswfalse\fi
  140. \let\\=\@eqncr
  141. $$\displ@@ \tabskip\@centering \halign to \displaywidth\bgroup
  142.   \global\@eqcnt\@ne\hfil
  143.   $\@lign\displaystyle{##}$\tabskip\z@skip&\global\@eqcnt\tw@
  144.   $\@lign\displaystyle{{}##}$\hfil\tabskip\@centering&
  145.   \llap{\@lign##}\tabskip\z@skip\crcr}
  146. \def\endeqalignno{\@@eqncr\egroup
  147.       \global\advance\c@equation\m@ne$$\global\@ignoretrue}
  148. \def\displ@@{\global\dt@ptrue\openup\jot\m@th % Remove \penalty from \displ@y
  149.   \everycr{\noalign{\ifdt@p \global\dt@pfalse
  150.       \vskip-\lineskiplimit \vskip\normallineskiplimit \fi}}}
  151. % Here's the eqalignno* environment:
  152. \@namedef{eqalignno*}{\@defeqnswfalse\eqalignno}
  153. \@namedef{endeqalignno*}{\endeqalignno}
  154. % Two formulas like \eqalignno (doesn't need the $$ $$)
  155. \def\eqaligntwo{\stepcounter{equation}\let\@currentlabel=\theequation
  156. \if@defeqnsw\global\@eqnswtrue\else\global\@eqnswfalse\fi
  157. \let\\=\@eqncr
  158. $$\displ@@ \tabskip\@centering \halign to \displaywidth\bgroup
  159.   \global\@eqcnt\m@ne\hfil
  160.   $\@lign\displaystyle{##}$\tabskip\z@skip&\global\@eqcnt\z@
  161.   $\@lign\displaystyle{{}##}$\hfil\qquad&\global\@eqcnt\@ne
  162.   \hfil$\@lign\displaystyle{##}$&\global\@eqcnt\tw@
  163.   $\@lign\displaystyle{{}##}$\hfil\tabskip\@centering&
  164.   \llap{\@lign##}\tabskip\z@skip\crcr}
  165. \def\endeqaligntwo{\@@eqncr\egroup
  166.       \global\advance\c@equation\m@ne$$\global\@ignoretrue}
  167. \@namedef{eqaligntwo*}{\@defeqnswfalse\eqaligntwo}
  168. \@namedef{endeqaligntwo*}{\endeqaligntwo}
  169. % subequations
  170. %%% File: subeqn.sty
  171. %%% The subequations environment %%%
  172. % Within the subequations environment, the only change is that
  173. % equations are labeled differently.  The number stays the same,
  174. % and lower case letters are appended.  For example, if after doing
  175. % three equations, numbered 1, 2, and 3, you start a subequations
  176. % environmment and do three more equations, they will be numbered
  177. % 4a, 4b, and 4c.  After you end the subequations environment, the
  178. % next equation will be numbered 5.
  179. % Both text and equations can be put inside the subequations environment.
  180. % If you make any improvements, I'd like to hear about them.
  181. % Stephen Gildea
  182. % MIT Earth Resources Lab
  183. % Cambridge, Mass. 02139
  184. % mit-erl!gildea
  185. % gildea@erl.mit.edu
  186. \newtoks\@stequation
  187. \def\subequations{\refstepcounter{equation}%
  188.   \edef\@savedequation{\the\c@equation}%
  189.   \@stequation=\expandafter{\theequation}%   %only want \theequation
  190.   \edef\@savedtheequation{\the\@stequation}% %expanded once
  191.   \edef\oldtheequation{\theequation}%
  192.   \setcounter{equation}{0}%
  193.   \def\theequation{\oldtheequation\alph{equation}}}
  194. \def\endsubequations{%
  195.   \ifnum\c@equation < 2 \@warning{Only \the\c@equation\space subequation
  196.     used in equation \@savedequation}\fi
  197.   \setcounter{equation}{\@savedequation}%
  198.   \@stequation=\expandafter{\@savedtheequation}%
  199.   \edef\theequation{\the\@stequation}%
  200.   \global\@ignoretrue}
  201. % More from John Hobby
  202. % Fix Plain's \bigl, \Bigl, etc. macros so that they try to scale with
  203. % LaTeX size changes.
  204. \ifx\selectfont\undefined    % nonNFSS version
  205. % This uses the fact that \@setsize sets \ht\strutbox
  206. % to be 70% of the normal unstretched baselineskip.
  207. % (Actually it doesn't, so we have to redefine \@setsize to define \strutboxa
  208. \newbox\strutboxa
  209. \def\@setsize#1#2#3#4{\@nomath#1\let\@currsize#1\baselineskip
  210.    #2\setbox\strutboxa\hbox{\vrule height.7\baselineskip
  211.       depth.3\baselineskip width\z@}\baselineskip\baselinestretch\baselineskip
  212.    \normalbaselineskip\baselineskip#3#4}
  213. \def\struta{\relax\ifmmode\copy\strutboxa\else\unhcopy\strutboxa\fi}
  214. \def\big#1{{\hbox{$\left#1\vcenter to1.428\ht\strutboxa{}\right.\n@space$}}}
  215. \def\Big#1{{\hbox{$\left#1\vcenter to2.142\ht\strutboxa{}\right.\n@space$}}}
  216. \def\bigg#1{{\hbox{$\left#1\vcenter to2.857\ht\strutboxa{}\right.\n@space$}}}
  217. \def\Bigg#1{{\hbox{$\left#1\vcenter to3.571\ht\strutboxa{}\right.\n@space$}}}
  218. \else % NFSS version
  219. % Change \fontsize so that it remembers the \baselineskip in \baselinex
  220. \newdimen\baselinex
  221. \newbox\strutboxa
  222. \def\fontsize#1#2{%
  223.     \edef\f@size{#1}%
  224.     \edef\setnew@baselineskip{\baselinex #2\relax\showthe\baselinex
  225.     \setbox\strutboxa\hbox{\vrule height.7\baselinex depth.3\baselinex width\z@}%
  226.     \baselineskip #2\relax}%
  227.     \edef\lcl@currsize{#1#2}}
  228. \baselinex=\baselineskip
  229. \def\struta{\relax\ifmmode\copy\strutboxa\else\unhcopy\strutboxa\fi}
  230. \def\big#1{{\hbox{$\left#1\vcenter to1.0\baselinex{}\right.\n@space$}}}
  231. \def\Big#1{{\hbox{$\left#1\vcenter to1.5\baselinex{}\right.\n@space$}}}
  232. \def\bigg#1{{\hbox{$\left#1\vcenter to2.0\baselinex{}\right.\n@space$}}}
  233. \def\Bigg#1{{\hbox{$\left#1\vcenter to2.5\baselinex{}\right.\n@space$}}}
  234. \fi % nonNFSS version
  235. % Finally, always put equation number in a box.  (Makes a difference when
  236. % text Roman is not the same as textfont0
  237. \def\@eqnnum{\mbox{\rm (\theequation)}}
  238. % modify \begin{equation} \end{equation} so it will take an optional arg.
  239. \def\equation{$$ % $$ BRACE MATCHING HACK
  240.     \@ifnextchar[%     ] BRACE MATCHING HACK
  241.     {\let\protect=\noexpand\@equation}%
  242.     {\refstepcounter{equation}}}
  243. \def\expandableref#1{\@ifundefined{r@#1}{??}%
  244.         {\expandafter\expandafter\expandafter\@car\csname r@#1\endcsname\@nil}}
  245. \let\@saveref=\ref
  246. \def\@equation[#1]{%
  247.     \let\ref=\expandableref
  248.     \edef\theequation{#1}%
  249. %\show\theequation
  250.     \let\@currentlabel=\theequation
  251.     \let\ref=\@saveref}
  252. \endinput
  253.